package org.harlov.testsys.views;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;

import javax.swing.JFrame;

import org.harlov.testsys.loger;
import org.harlov.testsys.db.users;


public class main_form extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	gui_factory gFactory ;
	
	JFrame mFrame ;
	
	
	
	public main_form() 
	{
		super();
		mFrame = this;
		String version = "0.1 alpha";
		gFactory = new gui_factory(this);
		
		this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);} });
		
		this.setPreferredSize(new Dimension(225,300));
		this.setSize(225,300);
		this.getContentPane().setLayout(null);
		this.setResizable(false);
		this.setTitle("Система тестирования HTest " + version);
		gui_factory.setCenterPosition(this);
		//this.setLayout(new FlowLayout());
		gFactory.newLabel("Логин"	,"l_login",	10,10);
		gFactory.newLabel("Пароль"	,"l_pass",	10,70);
		gFactory.newText("t_login",10, 50);
		gFactory.newPassField("p_pass", 10 , 110);
		gFactory.newButton("Войти","btn_login", 10, 150, new login_user() );
		
		
	
	}
	

	
	
//Event's list

	
class login_user implements ActionListener {

	@Override
	public void actionPerformed(ActionEvent arg0) {
	try {	
		String log = users.proc_login(gFactory.getTextFrom("t_login"),gFactory.getTextFrom("p_pass"));
			
			if (log.compareTo("AC1") == 0) {
				new stest_form(gFactory.getTextFrom("t_login"));
				mFrame.dispose();
			}
			if (log.compareTo("AC2") == 0) {
				new creators_form(gFactory.getTextFrom("t_login"));
				mFrame.dispose();
			}
			if (log.compareTo("AC3") == 0) {
				new admin_form(gFactory.getTextFrom("t_login"));
				mFrame.dispose();
			}
	}
	catch (SQLException e) {loger.add(e.getMessage(), this, 1);}
	
	
	
}	
}

class exit implements ActionListener {

	@Override
	public void actionPerformed(ActionEvent arg0) {
		
		
	}
	
}
	}


	

